package com.cqjtu.drive.controller;

import com.cqjtu.drive.pojo.Vehicle;
import com.cqjtu.drive.response.Response;
import com.cqjtu.drive.service.VehicleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author zxl
 * @Date 2024/6/17 12:49
 */
@RestController
public class VehicleController {
    @Autowired
    VehicleService vehicleService;

    @PostMapping("/api/vehicle/insert")
    public Response<String> insertVehicle(@RequestBody Vehicle vehicle){
        return vehicleService.insertVehicle(vehicle);
    }

    @PostMapping("/api/vehicle/update")
    public Response<String> updateVehicle(@RequestBody Vehicle vehicle){
        return vehicleService.updateVehicle(vehicle);
    }

    @PostMapping("/api/vehicle/delete")
    public Response<String> delete(@RequestParam String vId){
        return vehicleService.deleteVehicle(vId);
    }

    @PostMapping("/api/vehicle/getall")
    public Response<List<Vehicle>> getall(){
        return vehicleService.getAllVehicles();
    }

    @PostMapping("/api/vehicle/getByname")
    public Response<List<Vehicle>> getByname(@RequestParam String vName){
        return vehicleService.getVehiclesByname(vName);
    }

}
